<!DOCTYPE html>
<head>
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
  <title>Auto-revert metrics</title>
  <meta charset="utf-8">
  <link rel="stylesheet" href="/common.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script>
    function createUrl(parameters) {
      var params = [];
      for (var key in parameters) {
        if (parameters[key] != undefined) {
          params.push(key + '=' + parameters[key])
        }
      }

      if (params.length == 0) {
        return 'auto-revert-metrics';
      } else {
        return 'auto-revert-metrics?' + params.join('&');
      }
    };

    function getMetricsBetweenDateRange(e) {
      var parameters = {}
      parameters['start_date'] = $('#start_date').val() == 'mm/dd/yyyy' ? undefined : $('#start_date').val();
      parameters['end_date'] = $('#end_date').val() == 'mm/dd/yyyy' ? undefined : $('#end_date').val();
      newUrl = createUrl(parameters);
      window.location.replace(newUrl);
      e.preventDefault();
    };

    $(function() {
      $('#submit').click(getMetricsBetweenDateRange);
    });
  </script>
</head>
<body>
  <form>
    Start Date
    <input type="date" id="start_date" value={{ start_date }}></input>
    End Date
    <input type="date" id="end_date" value={{ end_date }}></input>
    <input type="submit" id="submit"></input>
  </form>
  <br>
  <b>Auto-revert metrics:</b><br>
  <table>
    <tr>
      <th>Metric</th>
      <th>Result</th>
    </tr>
    <tr>
      <td title="Tree closures due to compile failures">
        # of tree closures due to compile failures
      </td>
      <td>
        <table>
          <tr>
            <td title="All compile failures">Total</td><td>{{ tree_closures.total }}</td>
          </tr>
          <tr>
            <td>Manually-closed or auto-opened</td><td>{{ tree_closures.manually_closed_or_auto_opened}}</td>
          </tr>
          <tr>
            <td title="Status messages include 'flake', 'flaky' or 'bot failure'">Flakes</td><td>{{ tree_closures.flakes }}</td>
          </tr>
          <tr>
            <td title="Status messages include 'revert'">Reverts</td><td>{{ tree_closures.reverts }}</td>
          </tr>
          <tr>
            <td title="Unclear whether reliable or flaky failures">Others</td><td>{{ tree_closures.others }}</td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td title="Total number of culprits Findit found that needed reverting">
        # of culprits
      </td>
      <td>{{ revert_cls_detected }}</td>
    </tr>
    <tr>
      <td title="Total number of revert CLs Findit created">
        # of reverts created by Findit
      </td>
      <td>{{ revert_cls_created }}</td>
    </tr>
    <tr>
      <td title="Revert CLs Findit created that were committed">
        # of reverts created by Findit committed
      </td>
      <td>{{ revert_cls_committed }}</td>
    </tr>
    <tr>
      <td title="Findit created a revert CL for the suspected CL, but ultimately no revert CL by anyone was ever committed">
        # of false positives
      </td>
      <td>{{ false_positives }}</td>
    </tr>
    <tr>
      <td title="Findit created the revert CL before any sheriff">
        # Findit was faster
      </td>
      <td>{{ findit_faster }}</td>
    </tr>
    <tr>
      <td title="Findit determined a revert CL is needed, but by the time it did so a sheriff had already created and committed one for the same suspected CL">
        # Sheriffs were faster
      </td>
      <td>{{ sheriffs_faster }}</td>
    </tr>
    <tr>
      <td title="If the sheriffs were faster or slower than Findit">
        Findit vs Sheriffs speed
      </td>
      <td>
        <table>
          <tr>
            <td title="The average time (HH:MM:SS) Findit's revert CLs were faster than those of sheriffs. Only revert CLs by sheriffs that were committed are counted">
              Findit Faster (HH:MM:SS)
            </td>
            <td> {{ faster_than_sheriff_metrics.average }}</td>
          </tr>
          <tr>
            <td>90%</td>
            <td>{{ faster_than_sheriff_metrics.ninetieth_percentile }}</td>
          </tr>
          <tr>
            <td>70% </td>
            <td>{{ faster_than_sheriff_metrics.seventieth_percentile }}</td>
          </tr>
          <tr>
            <td>50%</td>
            <td>{{ faster_than_sheriff_metrics.fiftieth_percentile }}</td>
          </tr>
        </table>
        <br>
        <table>
          <tr>
            <td title="The average latency (HH:MM:SS) Findit's revert CLs were behind those of sheriffs. Only revert CLs by sheriffs that were committed are counted">
              Sheriffs Faster (HH:MM:SS)
            </td>
            <td> {{ slower_than_sheriff_metrics.average }}</td>
          </tr>
          <tr>
            <td>90%</td>
            <td>{{ slower_than_sheriff_metrics.ninetieth_percentile }}</td>
          </tr>
          <tr>
            <td>70% </td>
            <td>{{ slower_than_sheriff_metrics.seventieth_percentile }}</td>
          </tr>
          <tr>
            <td>50%</td>
            <td>{{ slower_than_sheriff_metrics.fiftieth_percentile }}</td>
          </tr>
        </table>
      </td>
    </tr>
  <table>
</body>
